package com.zwf.controller.user;

import com.zwf.constant.StatusConstant;
import com.zwf.dto.SetmealDTO;
import com.zwf.entity.Dish;
import com.zwf.entity.Setmeal;
import com.zwf.result.Result;
import com.zwf.service.SetmealService;
import com.zwf.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author zwf
 * @date 2024/2/6 21:50
 */

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Slf4j
@Api(tags = "套餐浏览接口")
public class SetmealController {

    @Autowired
    SetmealService setmealService;

    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> list(Long categoryId){
        log.info("根据分类id查询套餐：{}",categoryId);
        Setmeal setmeal=new Setmeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE);  //查询起售中的套餐
        List<Setmeal> list=setmealService.list(setmeal);
        return Result.success(list);
    }

    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询包含的菜品")
    public Result<List<DishItemVO>> queryDishByCategoryId(@PathVariable Long id){
        log.info("根据套餐id查询包含的菜品:{}",id);
        List<DishItemVO> dishItemVOList =setmealService.queryDish(id);
        return Result.success(dishItemVOList);
    }
}
